package com.yanqu.road.entity.systemloop;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@FieldTypeAnnotation(tableName = "t_c_system_loop")
public class SystemLoopData extends DataObject {
    @FieldTypeAnnotation(desc = "轮询id对应t_s_system_loop_config的id", select = true, update = true)
    private int loopId;
    @FieldTypeAnnotation(desc = "上一次轮询周id")
    private int lastWeekId;
    @FieldTypeAnnotation(desc = "当前轮询到的系统")
    private int systemId;
    @FieldTypeAnnotation(desc = "服务器列表")
    private Set<Long> serverIdSet = new HashSet<>();

    public SystemLoopData() {
    }

    public SystemLoopData(int loopId) {
        this.loopId = loopId;
        setInsertOption();
    }

    public int getLoopId() {
        return loopId;
    }

    public void setLoopId(int loopId) {
        this.loopId = loopId;
    }

    public int getLastWeekId() {
        return lastWeekId;
    }

    public void setLastWeekId(int lastWeekId) {
        if (this.lastWeekId != lastWeekId) {
            this.lastWeekId = lastWeekId;
            setUpdateOption();
        }
        this.lastWeekId = lastWeekId;
    }

    public int getSystemId() {
        return systemId;
    }

    public void setSystemId(int systemId) {
        if (this.systemId != systemId) {
            this.systemId = systemId;
            setUpdateOption();
        }
        this.systemId = systemId;
    }

    public Set<Long> getServerIdSet() {
        return serverIdSet;
    }

    public void setServerIdSet(Set<Long> serverIdSet) {
        this.serverIdSet = serverIdSet;
        setUpdateOption();
    }

    public void addServerId(long serverId) {
        if (this.serverIdSet.add(serverId)) {
            setUpdateOption();
        }
    }

    public void addServerIds(List<Long> serverIds) {
        this.serverIdSet.addAll(serverIds);
        setUpdateOption();
    }

    public void removeServerId(Long serverId) {
        if (this.serverIdSet.remove(serverId)) {
            setUpdateOption();
        }
    }
}
